using System;

namespace NopSolutions.NopCommerce.LuceneHelper.Tasks
{
    public class DelegateTask : BaseTask<DelegateTask>
    {
        #region Private

        private Action<IndexManager, SearchManager, IndexWriterWrapper> _function;
        private LuceneIndexType _indexType;

        #endregion

        #region Constructor

        public DelegateTask(Action<IndexManager, SearchManager, IndexWriterWrapper> function, LuceneIndexType indexType)
            : base(new Random().Next())
        {
            _function = function;
            _indexType = indexType;
        }

        #endregion

        #region Task

        public override void DoTask(IndexManager indexManager, SearchManager searchManager, IndexWriterWrapper indexer)
        {
            _function.Invoke(indexManager, searchManager, indexer);
        }

        public override LuceneIndexType IndexType
        {
            get { return _indexType; }
        }

        public override bool RebuildIndex
        {
            get { return false; }
        }

        #endregion
    }
}
